/**
 * $Id: SharedObjectMgr.as 601 2009-11-24 02:18:43Z kenhu $
 * */
package utils
{
	import flash.net.SharedObject;
	
	/**
	 * sharedObject操作類
	 * @author kenhu
	 * 
	 */	
	public class SharedObjectUtil
	{
		/**
		 * 獲取某路徑so
		 * @param p_type
		 * @param p_path
		 * @return 
		 * 
		 */		
		private static function getSo(p_type:String, p_path:String = null):SharedObject
		{
			var path:String = p_path;
			if(path)
				path += "/";
			else
				path = "";
			return SharedObject.getLocal(path + p_type, "/");
		}
		
		/**
		 * 獲取某路徑下某個sharedObject
		 * @param p_type
		 * @param p_path
		 * @return 
		 * 
		 */			
		public static function getInfo(p_type:String, p_path:String = null):Object
		{
			return getSo(p_type, p_path).data[p_type];
		}
		
		/**
		 * 保存sharedObject
		 * @param p_type
		 * @param p_path
		 * @param p_data
		 * 
		 */			
		public static function saveInfo(p_type:String, p_data:Object, p_path:String = null):String
		{
			var tmpSo:SharedObject = getSo(p_type, p_path);
			tmpSo.setProperty(p_type, p_data);
			return tmpSo.flush();
		}
		
		/**
		 * 移除單項信息
		 * @param p_type
		 * @param p_path
		 * 
		 */			
		public static function removeInfo(p_type:String, p_path:String = null):void
		{
			var tmpObject:SharedObject = getSo(p_type, p_path);
			tmpObject.close();
			tmpObject.clear();
		}
	}
}